# ./docker/php/8.3/Dockerfile
FROM php:8.3-fpm

# 設定 www-data 用戶的 UID/GID 與外部用戶相同
ARG USER_ID=1000
ARG GROUP_ID=1000
RUN usermod -u ${USER_ID} www-data && groupmod -g ${GROUP_ID} www-data

# 设置时区为上海
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 安裝必要套件與 Laravel 常用 PHP 擴展
RUN apt-get update && apt-get install -y \
  git \
  unzip \
  zip \
  libzip-dev \
  libxml2-dev \
  libonig-dev \
  libcurl4-openssl-dev \
  libpng-dev \
  libjpeg-dev \
  libfreetype6-dev \
  libwebp-dev \
  libxpm-dev \
  libssl-dev \
  libicu-dev \
  && docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
  && docker-php-ext-install \
    pdo \
    pdo_mysql \
    mbstring \
    xml \
    curl \
    zip \
    bcmath \
    opcache \
    gd \
    intl \
    exif \
    pcntl \
    sockets \
    calendar \
    gettext

# 複製自訂 php.ini 設定
COPY php.ini /usr/local/etc/php/php.ini

# 安裝 Redis 擴展
RUN pecl install redis && docker-php-ext-enable redis

# 安装 Composer 2.8
RUN curl -sS https://getcomposer.org/installer | php -- --version=2.8.0 --install-dir=/usr/local/bin --filename=composer

# 设置 Composer 全局阿里云镜像
RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/